package com.servicesystem.servicesystem.controller.douyin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.servicesystem.servicesystem.entity.AliGoodsLib;
import com.servicesystem.servicesystem.entity.douyin.Order;
import com.servicesystem.servicesystem.entity.douyin.vo.order.OrderLogisticsAddVO;
import com.servicesystem.servicesystem.entity.douyin.vo.order.OrderTimeVO;
import com.servicesystem.servicesystem.service.OrderService;
import com.servicesystem.servicesystem.untis.R;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author X
 * @since 2020-09-11
 */
@RestController
@RequestMapping("/douyin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    /***
     * 获取订单列表
     * @return
     */
    @PostMapping("/getOrderList/{pageNum}/{pageSize}")
    public R getOrderList(@RequestBody OrderTimeVO orderTimeVO,
                          @PathVariable(value = "pageNum") String page,
                          @PathVariable(value = "pageSize") String size) throws Exception {
        System.out.println(orderTimeVO);
        String startTime = orderTimeVO.getStartTime();
        String endTime = orderTimeVO.getEndTime();
        String list = orderService.getOrderInfoList(startTime, endTime, page, size);
        if (list == null) {
            return R.fail("{\"total\":0,\"count\":0}");
        }
        return R.success(list);
    }

    /***
     * 获取订单
     * @return
     */
    @PostMapping("/getOrderOne/{orderId}")
    public R getOrderOne(@PathVariable("orderId") String orderId) throws Exception {
        String result = orderService.getOrderOne(orderId);
        return R.success(result);
    }

    /***
     * 查看订单中有多少没有评论数量
     * @return
     */
    @GetMapping("/getIsCommentCount")
    public R getIsCommentCount() {
        int count = orderService.getIsCommentCount();
        return R.success(count);
    }

    /***
     * 给未评价的用户发送短信
     * @return
     */
    @PostMapping("/sendSMS")
    public R sendSMS() {
        int count = orderService.sendSMS();
        return R.success("短信发送成功");
    }

    /***
     * 给未评价的用户发送短信 个人
     * @return
     */
    @PostMapping("/sendPhoneSMS/{phone}")
    public R sendPhoneSMS(@PathVariable(value = "phone") String phone) {
        int count = orderService.sendPhoneSMS(phone);
        return R.success("短信发送成功");
    }


    /***
     * 订单处理 获取订单列表
     * @return
     */
    @PostMapping("/getSQLOrderList/{pageNum}/{pageSize}")
    public R getOrderList(@PathVariable(value = "pageNum") Long pageNum,
                          @PathVariable(value = "pageSize") Long pageSize,
                          @RequestBody Order order) {
        Page<Order> orderPage = new Page<>(pageNum, pageSize);
        Page<Order> page = orderService.getOrderList(orderPage,order);
        return R.success(page);
    }

    /***
     * 订单发货
     * @return
     */
    @PostMapping("/orderLogisticsAdd")
    public R orderLogisticsAdd(@RequestBody OrderLogisticsAddVO orderLogisticsAddVO) throws UnsupportedEncodingException {
        String result = orderService.orderLogisticsAdd(orderLogisticsAddVO);
        return R.success(result);
    }

    /***
     * 获取快递公司列表
     * @return
     */
    @GetMapping("/logisticsCompanyList")
    public R logisticsCompanyList() throws UnsupportedEncodingException {
        String result = orderService.logisticsCompanyList();
        return R.success(result);
    }

    /***
     * 1688发货成功修改发货状态
     * @return
     */
    @PostMapping("/upDataOrderOrderStatus")
    public R upDataOrderOrderStatus(@RequestParam String orderId) {
        orderService.upDataOrderOrderStatus(orderId);
        return R.success();
    }

    /***
     * 消息订阅 订单创建 TODO
     * @param pId
     * @return
     */
    /*@PostMapping("/tradeTradeCreate")
    public R tradeTradeCreate(@RequestParam String pId) throws UnsupportedEncodingException {
        Order order = orderService.tradeTradeCreate(pId);
        return R.success(order);
    }*/
}

